<div>
    <form class="layui-form" action="" lay-filter="testform">
        <div class="layui-form-item">
            <label class="required">公式编码</label>
            <input name="ftagname" type="text" class="layui-input" placeholder="请输入公式编码" required  lay-verify="required" id="ftagname">
        </div> 
        <div class="layui-form-item">
            <label class="required">公式名称</label>
            <input name="fname" type="text" class="layui-input" placeholder="请输入公式名称" required  lay-verify="required" id="fname">
        </div>
        <div class="layui-form-item">
            <label class="required">公式类型</label>
            <select name="ftype" lay-verify="required" id="ftypes" required  lay-verify="required">
                <option value="1">计算点</option>
                <option value="2">用户点</option>
            </select>
        </div>
        <div class="layui-form-item">
            <label class="required">公式内容</label>
            <div style="display:flex">
                <input name="formula" disabled required  lay-verify="required" type="hidden" class="layui-input" placeholder="请编辑公式内容"  
                style="width:90%;background-color: #e9e9e9;border: 1px solid #eee;cursor: not-allowed;" 
                id="formula">
                <input name="formulaview" disabled required  lay-verify="required" type="text" class="layui-input" placeholder="请编辑公式内容"  
                style="width:90%;background-color: #e9e9e9;border: 1px solid #eee;cursor: not-allowed;" 
                id="formulaview">
                
                <button type="button" class="layui-btn" onclick="formula_edit()">编辑公式</button>
            </div>
        </div>
        <div class="layui-form-item">
            <label>详细说明</label>
            <input name="remark" type="text" class="layui-input" placeholder="请输入说明" id="remark">
        </div>
        
        <button type="button" class="layui-btn" lay-submit lay-filter="LAY-formula-add">提交</button>

        
    </form>

    <script type="text/html" template lay-done="layui.data.getData(d.params)">
    </script>

</div>

<script>
        layui.use(['admin', 'laytpl', 'form', 'laypage', 'layer', 'view',
        'setter', 'upload','laydate'
    ], function () {
        var $ = layui.$,
            admin = layui.admin,
            table = layui.table,
            laytpl = layui.laytpl,
            form = layui.form,
            laypage = layui.laypage,
            layer = layui.layer,
            laydate = layui.laydate
            view = layui.view,
            setter = layui.setter;
            form.render(); 

            layui.data.getData = function (data){
                if(data.ftagname != undefined){
                $('#ftagname').val(data.ftagname)
                $('#fname').val(data.fname)
                $('#formula').val(data.formula)
                $('#formulaview').val(data.formulaviwe)
                $('#remark').val(data.Remark)
                $('#ftypes').val(data.ftype);
                form.render();
                }
            }
             
        

            $.ajax({
                type: 'get',
                dataType: 'text',
                headers: {
                    Accept: "application/json; charset=utf-8"
                },
                url: 'http://www.iotddc.com/lmcomputer/bemFloorTree',
                data: {
                    token: 'EEAADD2299AAEE226677331177885599',
                    parentId: 100
                },
                success: function (data) {
                    treeData = data;
                }
            })


            formula_edit = function(){
                admin.popup({
                    title:'编辑公式',
                    area:['1200px','660px'],
                    id:'LAY-APP-popup-computer',
                    success:function(layero,index){
                        var formula = $('#formula').val()
                        var formulaview = $('#formulaview').val()
                        view(this.id).render('/formula/formula-popup-computer',{treeData:treeData,formula,formulaview}).done(function(){
                           
                            form.on('submit(formDemo)',
                                data => {
                                    var formula = data.field.title;
                                    var formulaview = data.field.title2
                                    $('#formula').val(formula)
                                    $('#formulaview').val(formulaview)
                                    layer.close(index)
                                    
                                })
                        })
                    }
                })
            }
    })
</script>